package com.dexilaonian.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.RecoveryAdapter;
import com.dexilaonian.fragment.Nursing_DocFragment;
import com.dexilaonian.fragment.NursingtFragment;
import com.dexilaonian.fragment.ProjectFragment;
import com.dexilaonian.fragment.YiyangFragment;
import com.dexilaonian.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HomeNursingActivity extends BaseActivity
        implements View.OnClickListener {
    String[] titles = new String[]{"护理项目", "护理医师"};
    @Bind(R.id.recovery_v1)
    View recoveryV1;
    @Bind(R.id.recovery_v2)
    View recoveryV2;
    private List<Fragment> fragments_list = new ArrayList<>();
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.et_sou_text)
    EditText  etSouText;
    @Bind(R.id.tv_search)
    TextView  tvSearch;
    @Bind(R.id.recovery_project)
    TextView  recoveryProject;
    @Bind(R.id.recoveryyishi)
    TextView  recoveryyishi;
    @Bind(R.id.recovery_viewpager)
    ViewPager recoveryViewpager;
    private NursingtFragment nursingtFragment;
    private Nursing_DocFragment  nursingdocFragment;
    private RecoveryAdapter recoveryAdapter;
    private String          city;
    @Override
    public int getLayoutID() {
        return R.layout.activity_recovery;
    }

    @Override
    public void initView() {
        nursingtFragment = new NursingtFragment();
        nursingdocFragment = new Nursing_DocFragment();
        fragments_list.add(nursingtFragment);
        fragments_list.add(nursingdocFragment);
        recoveryAdapter = new RecoveryAdapter(HomeNursingActivity.this.getSupportFragmentManager(),fragments_list);
    }
    @Override
    protected void initData() {
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        recoveryProject.setOnClickListener(this);
        recoveryyishi.setOnClickListener(this);
        recoveryViewpager.setAdapter(recoveryAdapter);
        recoveryViewpager.setCurrentItem(0);
        recoveryViewpager.setOffscreenPageLimit(2);
        recoveryViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position,float positionOffset,int positionOffsetPixels){
            }

            @Override
            public void onPageSelected(int position) {
                changeTextColor(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void changeTextColor(int position) {
        if (position == 0) {
            recoveryProject.setTextColor(Color.parseColor("#009a99"));
            recoveryyishi.setTextColor(Color.parseColor("#333333"));
            recoveryV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
            recoveryV2.setBackground(null);

        } else if (position == 1) {
            recoveryyishi.setTextColor(Color.parseColor("#009a99"));
            recoveryProject.setTextColor(Color.parseColor("#333333"));
            recoveryV1.setBackground(null);
            recoveryV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
        }
    }

    @OnClick({R.id.back,
              R.id.tv_search,
              R.id.recovery_project,
              R.id.recoveryyishi})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
		/*	case R.id.tv_search:
				break;*/
            case R.id.recovery_project:
                recoveryViewpager.setCurrentItem(0);
                recoveryProject.setTextColor(Color.parseColor("#009a99"));
                recoveryyishi.setTextColor(Color.parseColor("#333333"));
                recoveryV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                recoveryV2.setBackground(null);
                break;
            case R.id.recoveryyishi:
                recoveryViewpager.setCurrentItem(1);
                recoveryyishi.setTextColor(Color.parseColor("#009a99"));
                recoveryProject.setTextColor(Color.parseColor("#333333"));
                recoveryV1.setBackground(null);
                recoveryV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                break;
        }
    }
}
